﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using ML.Entity;
using ML.IBusiness;

namespace ML.WxLite.WebApi.ChineseRestaurant.Controllers
{
    public class PlatformCategoryController : BaseApiController
    {
        /// <summary>
        /// 店铺分类
        /// </summary>
        private readonly IPlatFormCategoryBusiness _platformBusiness;
        public PlatformCategoryController(IPlatFormCategoryBusiness platformBusiness)
        {
            _platformBusiness = platformBusiness;
        }

        /// <summary>
        /// 查询：所有可用的未删除店铺分类列表
        /// </summary>
        /// <returns></returns>
        [Route("api/wxlite/platform/getallenablelist")]
        [HttpGet]
        public IHttpActionResult GetAllEnableList()
        {
            var data = _platformBusiness.GetAllEnableList();
            var dto = new List<List<PlatformCategoryEntity>>();

            var count = 0;
            var index = 0;
            var array = new List<PlatformCategoryEntity>();
            foreach (var entity in data.data)
            {

                array.Add(new PlatformCategoryEntity { CreateTime = entity.CreateTime, DelMark = entity.DelMark, Enable = entity.Enable, Id = entity.Id, Name = entity.Name, PreviewImg = entity.PreviewImg });
                if (array.Count == 8)
                {
                    dto.Add(array);
                    count = -1;
                    array = new List<PlatformCategoryEntity>();
                }

                if (index == data.data.Count() - 1)
                {
                    dto.Add(array);
                }

                index++;
                count++;
            }
            return Json(dto);
        }
    }
}